package api

import (
	"gintest/kernel"
	"gintest/model"
	"github.com/gin-gonic/gin"
	"math/rand"
	"net/http"
	_ "strconv"
	"time"
)
const SUCCESS_CODE = 200
func Test(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"status": SUCCESS_CODE,
		"msg":"test",
	})
	return
}

func Index(c *gin.Context) {
	c.HTML(http.StatusOK, "index.html", gin.H{
		"title": "测试",
	})
}

func randNum() int {
	rand.Seed(time.Now().Unix())
	return rand.Intn(100)
}

func SearchDemo(c *gin.Context){
	//生成随机时间
	//randNum := randNum()
	//if randNum % 2 == 0 {
	//	time.Sleep(time.Second * 5)
	//}
	db := kernel.GetDB()
    var rows []model.Address
	db.Find(&rows)
	c.JSON(http.StatusOK, gin.H{
		"status": SUCCESS_CODE,
		"data":rows,
	})
}
